<script setup>
  import { ossImg } from "@/utils/utils";
  import { onMounted } from "vue";

  const emits = defineEmits(['close'])
  const emdlz = getApp().emdlz2
  const props = defineProps({
    resultCode: {
      type: Number || String,
      default: 0
    }
  })

  onMounted(() => {
    switch (props.resultCode) {
      // 字符串输入有误
      case 400:
        emdlz('track','event','Oreo_eggy_code_error_page','click','tips_show_up','');
        break;
      case 4000:
        emdlz('track','event','Oreo_eggy_scan_error_page','click','tips_show_up1','');
        break;
      case 4001:
        emdlz('track','event','Oreo_eggy_scan_code_page','click','tips_show_up2','');
        break;
      case 4002:
        emdlz('track','event','Oreo_eggy_beredeem_page','click','tips_show_up3','');
        break;
      case 'err':
        emdlz('track','event','Oreo_eggy_other_page','view','other_page','');
        break;
    }
  })

  const handleCloseModal = () => {
    switch (props.resultCode) {
      case 400:
        emdlz('track','event','Oreo_eggy_code_error_page','click','close_error_tips','');
        break;
      case 4000:
        emdlz('track','event','Oreo_eggy_scan_error_page','click','close_error_tips1','');
        break;
      case 4001:
        emdlz('track','event','Oreo_eggy_scan_code_page','click','close_error_tips2','');
        break;
      case 4002:
        emdlz('track','event','Oreo_eggy_beredeem_page','click','close_error_tips3','');
        break;
      case 'err':
        emdlz('track','event','Oreo_eggy_other_page','click','back_other','');
        break;
    }
    emits('close')
  }
</script>

<template>
  <view class="result-modal">
    <view class="dialog-body" :class="{ err: props.resultCode === 'err' }">
      <image
        class="close-icon"
        :src="ossImg('others/2025OreoXEggyParty/dialog/close.png')"
        @click.stop="handleCloseModal"
      />
      <image
        class="result-image"
        :src="ossImg(`others/2025OreoXEggyParty/dialog/${props.resultCode}.png`)"
      ></image>
      <image
        class="back-btn"
        :src="ossImg('others/2025OreoXEggyParty/dialog/btn_back.png')"
        @click.stop="handleCloseModal"
      ></image>
    </view>
  </view>
</template>

<style lang="scss" scoped>
.result-modal {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  z-index: 99;
  &::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .6);
    z-index: -1;
  }
  .dialog-body {
    width: 308px;
    height: 330px;
    position: relative;
    transform: translate(0, -70px);
    &.err {
      width: 308px;
      height: 330px;
    }
    .result-image {
      width: 100%;
      height: 100%;
    }
    .back-btn {
      width: 97px;
      height: 34px;
      position: absolute;
      top: 218px;
      right: 106px;
    }
    .close-icon {
      width: 36px;
      height: 36px;
      position: absolute;
      top: 48px;
      right: 3px;
      z-index: 2;
    }
  }
}
</style>
